<?php
/*
php标准格式；
学习模板！
*/
header("content-type:text/html;charset=UTF-8");
if(!empty($_POST))
{
$m_id = is_numeric($_POST["_id"]) ? $_POST["_id"] : null;
$m_chinese = is_numeric($_POST["_chinese"]) ? $_POST["_chinese"] :null;
$m_math = is_numeric($_POST["_math"]) ? $_POST["_math"] : null;
$m_name = is_null($_POST["_math"]) ? null : $_POST["_name"];
$m_english = is_numeric($_POST["_english"]) ? $_POST["_english"] : null;
if($m_id==null || $m_chinese==null || $m_math==null || $m_name==null || $m_english==null)
{
	echo "<script type ='text/javascript'>
	alert('非法的数据提交!');
	location.href='index.php';
	</script>";
}
  require 'connect.php';
  /*开始拼装sql语句*/
  $_sql = "select name from students where name ='{$m_name}';";
  /*先查询是否有和这个学生*/
    $resque = mysql_query($_sql);
    if(mysql_num_rows($resque)!=0)
    {
          echo "<script type='text/javascript'>
    alert('已经存在这个学生的信息了');
    location.href='index.php';
    </script>";
    exit;
    }

    /*开始拼装sql语句*/
  $_sql = "insert into students values({$m_id},'{$m_name}',{$m_chinese},{$m_math},{$m_english});";
  if(mysql_query($_sql))
  {
  	echo "<script type='text/javascript'>
		alert('添加成功');
            location.href='index.php';
  	</script>";
     /*关闭数据库*/
 mysql_close($_link);
 exit;
  }
 else
 {
 	echo "<script type='text/javascript'>
		alert('添加失败！');
    location.href='index.php';
  	</script>";
     /*关闭数据库*/
 mysql_close($_link);
    exit;
 }
}
?>